package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import cn.itcast.user.vo.PatternProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope//配置@Value注解实现配置信息的热更新
public class UserController {

    @Autowired
    private UserService userService;

//    @Value("${pattern.dateformat}")
//    private String dateFormat;
    @Autowired
    private PatternProperties patternProperties;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id,@RequestHeader(value = "Truth",required = false) String info) {
        User user = userService.queryById(id);
        user.setUsername(user.getUsername()+patternProperties.getDateformat());
        return user;
    }

    /**
     * http：localhost:8081/user/getUserInfo?userName=xxx&age=xxx
     * @param userName
     * @param age
     * @return
     */
    @GetMapping("/getUserInfo")
    public String getUserInfo(String userName,Integer age){
        return userName+age;
    }
}
